package com.yiwei.zhh.api.requestInfo;

import android.text.TextUtils;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.BeeCloudBean;
import com.yiwei.zhh.api.bean.GogoPayBean;
import com.yiwei.zhh.api.bean.HuaKouBean;
import com.yiwei.zhh.api.bean.PayOrderBean;
import com.yiwei.zhh.api.bean.RepayStatusDialogBean;
import com.yiwei.zhh.api.bean.RepayingDealBean;
import com.yiwei.zhh.api.callback.PaySelectContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class PaySelectRequest extends BaseRequest<PaySelectContract.View> implements PaySelectContract.Presenter<PaySelectContract.View> {

    public static PaySelectRequest create() {
        return new PaySelectRequest();
    }

    //    success - 成功、 failed - 失败
    public String SUCCESS = "success";
    public String FAILED = "failed";

//    @Override
//    public void getGoPay(String money) {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
//        mView.onRequestStart();
//        GogoPayBean bean = new GogoPayBean();
//        bean.money = money;
//        Api.api_service.gotoPay(bean).compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.getGoPaySuccess(result);
//                });
//    }
//
//    @Override
//    public void getBeeCloud(String action, String channel, String bill_no, String title, int total_fee) {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
//        mView.onRequestStart();
//        BeeCloudBean bean = new BeeCloudBean();
//        bean.action = action;
//        bean.channel = channel;
//        bean.bill_no = bill_no;
//        bean.title = title;
//        bean.total_fee = total_fee;
//        Api.api_service.getBeeCloud(bean).compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.getBeeCloudSuccess(result, channel);
//                });
//    }

//    @Override
//    public void getPayWay() {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
////        mView.onRequestStart();
//        Api.api_service.getPayWay().compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.getPayWaySuccess(result);
//                });
//    }

//    @Override
//    public void getPayOrder(String action, String payment_id, String channel, String money, String offset_money, String coupon_ids, String payment_account) {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
//        mView.onRequestStart();
//        PayOrderBean bean = new PayOrderBean();
//        bean.action = action;
//        bean.payment_id = payment_id;
//        bean.channel = channel;
//        bean.money = money;
//        bean.offset_money = offset_money;
//        bean.payment_account = payment_account;
//        if (TextUtils.isEmpty(coupon_ids)) {
//            coupon_ids = "";
//        }
//        bean.coupon_ids = coupon_ids;
//        Api.api_service.getPayOrder(bean).compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.getPayOrderSuccess(result);
//                });
//    }
//
//    @Override
//    public void getRepayDialog() {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
//        mView.onRequestStart();
//
//        Api.api_service.getRepayDialog().compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.getRepayDialogSuccess(result);
//                });
//    }
//
//    @Override
//    public void confirmDialog(String notice_id, String confirm) {
//        if (!Network.checkNetwork(BaseContext)) {
//            ToastUtil.makeText(BaseContext, networkFail).show();
//            return;
//        }
//        mView.onRequestStart();
//        RepayStatusDialogBean bean = new RepayStatusDialogBean();
//        bean.notice_id = notice_id;
//        bean.confirm = confirm;
//        Api.api_service.getConfirmDilaog(bean).compose(RxLifeUtil.checkOn(BaseContext)).
//                doFinally(() -> {
//                    try {
//                        mView.complete();
//                    } catch (NullPointerException e) {
//
//                    }
//                }).
//                subscribe(result -> {
//                    mView.confirmDialogSuccess(result, confirm);
//                });
//    }

    @Override
    public void getRepayData(String bank_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        RepayingDealBean bean = new RepayingDealBean();
        if (TextUtils.isEmpty(bank_id)) {
            bank_id = "";
        }
        bean.bank_id = bank_id;
        Api.api_service.getRepayInfo(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getRepayDataSuccess(result);
                });
    }

    @Override
    public void getHuaKou(String deal_id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        HuaKouBean bean = new HuaKouBean();
        bean.deal_id = deal_id;
        Api.api_service.getHuaKou(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getHuaKouSuccess(result);
                });
    }

    @Override
    public void getPayWay() {

    }

    @Override
    public void getDealBefore() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getDealBeforeV3().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getDealBefore(result);
                });
    }
}
